import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { operateReducerInitState } from "@/constant";
import { produce } from "immer";
import type {
  ReducerInitStateType,
  operateReducerInitStateType,
} from "@/types/reducer";
const operateSlice = createSlice({
  name: "operate",
  initialState: {
    operate: operateReducerInitState,
  },
  //相当于reducer
  reducers: {
    //设置运维支撑数据
    setOperateData: produce(
      (
        state: ReducerInitStateType,
        action: PayloadAction<operateReducerInitStateType>
      ) => {
        state.operate = action.payload;
      }
    ),
    //重置数据
    resetOperateData: produce((state: ReducerInitStateType) => {
      state.operate = operateReducerInitState;
    }),
  },
});

//导出action，在组件中用
export const { setOperateData,resetOperateData } = operateSlice.actions;
export default operateSlice.reducer;
